//
//  AlbumDetailsViewController.m
//  SuperRadio
//
//  Created by Damon on 14/12/17.
//  Copyright (c) 2014年 三个臭皮匠. All rights reserved.
//

#import "AlbumDetailsViewController.h"
#import "HostViewController.h"
#import "NetHandler.h"
#import "UIImageView+WebCache.h"
#import "Introduction.h"
#import "AlbumDatailsOfList.h"
#import "AlbumDetailsCell.h"
#import "AlbumDetailsInformationCell.h"
#import "AlbumOfList.h"
#import "AlbumOfListCell.h"
#import "UIScrollView+MJRefresh.h"
#import "UIScrollView+Extension.h"
#import "MainPlayerViewController.h"

#import "AudioPlayer.h"
#import "AudioButton.h"

#define DETAIL_HIGHT 180  // 显示图片的高度
#define FINAL_HIGHT 64    // 上拉滑动最终留下的显示图片高度
#define IMAGEVIEW_ORIGIN_Y - 60  // 图片的实际起点纵坐标
#define IMAGEVIEW_ORIGIN_HEITH 400  // 图片的实际高度

@interface AlbumDetailsViewController ()<UITableViewDataSource, UITableViewDelegate>

@property(nonatomic, retain) UITableView *detailsTableView;
@property(nonatomic, retain) NSMutableArray *listArr;
@property(nonatomic, retain) NSMutableArray *relatedArr;
@property(nonatomic, retain) NSMutableArray *inforArr;
@property(nonatomic, retain) NSMutableArray *arr;
@property(nonatomic, retain) UISegmentedControl *segment;

@property (nonatomic, retain)AudioButton *audioBtn;
//
@property(nonatomic, retain) Introduction *introduction;
@property(nonatomic, assign) NSInteger flag;
// 顶部背景图片
@property (nonatomic, retain)UIImageView *imageView;
// 专辑图片
@property(nonatomic, retain) UIImageView *albumImageView;
// 播主头像
@property(nonatomic, retain) UIImageView *avatarImageView;
// 播主名字
@property(nonatomic, retain) UILabel *nickname;
// 访问播主按钮
@property(nonatomic, retain) UIButton *linkNikeButton;

@property(nonatomic, retain) NSString *mark;

@property(nonatomic, retain) MainPlayerViewController *mainPlayVC;


// 当前的请求页数
@property (nonatomic, assign) NSInteger pageId;
// 最大得页数
@property (nonatomic, assign) NSInteger maxPageId;

// 当前的请求页数
@property (nonatomic, assign) NSInteger albumPageId;
// 最大得页数
@property (nonatomic, assign) NSInteger maxAlbumPageId;


@property (nonatomic, assign) NSInteger cellTag;


@property (nonatomic, retain)AlbumDetailsCell *cell;

@property (nonatomic, retain) UIView *whiteView;

@end

@implementation AlbumDetailsViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self listHandleData];
    self.cellTag = 0;


    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationItem.title = @"专辑详情";
    
    
    self.segment = [[UISegmentedControl alloc]initWithItems:[NSArray arrayWithObjects:@"简介",@"列表",@"相关专辑", nil]];
    self.segment.selectedSegmentIndex = 1;
    self.segment.alpha = 1;
    self.segment.backgroundColor = [UIColor clearColor];
    self.segment.frame = CGRectMake(0, 5, self.view.frame.size.width, 30);
    [self.segment addTarget:self action:@selector(changeSegment:) forControlEvents:UIControlEventValueChanged];
    [_segment release];
    
    
    // 创建一个播主信息背后的imageview
    self.imageView = [[UIImageView alloc] initWithFrame:CGRectMake(self.view.frame.origin.x, IMAGEVIEW_ORIGIN_Y, self.view.frame.size.width, IMAGEVIEW_ORIGIN_HEITH)];
    self.imageView.alpha = 0.1;
    [self.view addSubview:_imageView];
    
    
//    // 添加view
//    self.whiteView = [[UIView alloc] initWithFrame:CGRectMake(self.view.frame.origin.x, 200, self.view.frame.size.width, self.view.frame.size.height - 200)];
//    self.whiteView.backgroundColor = [UIColor whiteColor];
//    [self.view addSubview:self.whiteView];
//    self.whiteView.hidden = YES;
//    [_whiteView release];
    
    
    
    // 创建tableView
    self.detailsTableView = [[UITableView alloc] initWithFrame:CGRectMake(self.view.frame.origin.x, FINAL_HIGHT, self.view.frame.size.width, self.view.frame.size.height - FINAL_HIGHT) style:UITableViewStylePlain];
    // 不显示滚动条
   self.detailsTableView.showsVerticalScrollIndicator = NO;
    self.detailsTableView.backgroundColor = [UIColor clearColor];
    self.detailsTableView.delegate = self;
    self.detailsTableView.dataSource = self;
    self.detailsTableView.sectionHeaderHeight = 40;
    self.detailsTableView.contentInset = UIEdgeInsetsMake(0, 0, 70, 0);
    [self.view addSubview:self.detailsTableView];
    
    // 创建一个空白的FooterView
    self.detailsTableView.tableFooterView = [[[UIView alloc] init] autorelease];
    
    [_detailsTableView release];
    
    // 用一个透明的view作为tableview的headerview
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, DETAIL_HIGHT - FINAL_HIGHT)];
    // 把它设为no不会渲染它，效率略高点儿，不明显
   view.opaque = NO;
    
    //  self.table.contentInset = UIEdgeInsetsMake(240, 0, 0, 0);  //没有用这个方法是因为UITableViewStylePlain的section title 会停留在DETAIL_HIGHT的位置
    self.detailsTableView.tableHeaderView = view;
    
    // 注册cell类
   // [self.detailsTableView registerClass:[AlbumDetailsCell class] forCellReuseIdentifier:@"datails"];
    [self.detailsTableView registerClass:[AlbumDetailsInformationCell class] forCellReuseIdentifier:@"detailsInfor"];
    [self.detailsTableView registerClass:[AlbumOfListCell class] forCellReuseIdentifier:@"datailsRelated"];
    
    // 设置专辑图片
    self.albumImageView = [[UIImageView alloc]initWithFrame:CGRectMake(30, 20, 80, 80)];
    [view addSubview:self.albumImageView];
    [_albumImageView release];
    
    // 设置播主图片
    self.avatarImageView = [[UIImageView alloc] initWithFrame:CGRectMake(120, 20, 30, 30)];
    [view addSubview:self.avatarImageView];
    [_avatarImageView release];
    
    // 播主名字
    self.nickname = [[UILabel alloc] initWithFrame:CGRectMake(160, 20, 150, 20)];
    [view addSubview:self.nickname];
    [_nickname release];
    
    // 访问播主按钮
    self.linkNikeButton = [UIButton buttonWithType:UIButtonTypeSystem];
    self.linkNikeButton.frame = CGRectMake(140, DETAIL_HIGHT - FINAL_HIGHT - 40, 60, 20);
    [self.linkNikeButton addTarget:self action:@selector(visitNikeButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
        [view addSubview:self.linkNikeButton];
    
    // 调用下拉加载方法
    [self setupRefresh];
}


- (void) visitNikeButtonClicked:(UIButton *)button
{
    
    HostViewController *albumDetailsVC = [[HostViewController alloc] init];
    albumDetailsVC.introduction = self.introduction;
    [self.navigationController pushViewController:albumDetailsVC animated:YES];
    [albumDetailsVC release];

}

- (void)setNickInfor:(Introduction *)introduction
{
    [self.imageView setImageWithURL:[NSURL URLWithString: [[introduction coverWebLarge] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]];
    [self.albumImageView setImageWithURL:[NSURL URLWithString: [[introduction coverWebLarge] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]];
    [self.avatarImageView setImageWithURL:[NSURL URLWithString: [[introduction avatarPath] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]];
    
    [self.linkNikeButton setTitle:@"访问播主" forState:UIControlStateNormal];

    self.nickname.text = introduction.nickname;

}

#pragma mark 图片拖拽效果 方法
//   效果都在这个方法里写的
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    CGFloat content = scrollView.contentOffset.y;
    CGRect newFrame = self.imageView.frame;
    // 判断当前偏移状态
    if (content < 0) {
        // imageView的frame改变要小于偏移量
        newFrame.origin.y = IMAGEVIEW_ORIGIN_Y - content / 5;
        self.imageView.frame = newFrame;
        
    } else if (content >= 0 && content < DETAIL_HIGHT) {
        // imageView的frame改变要等于偏移量
        newFrame.origin.y = IMAGEVIEW_ORIGIN_Y - content;
        self.imageView.frame = newFrame;
    }
}

// 导航栏右侧按钮点击
- (void)clicked:(UIBarButtonItem *)barButton
{
    HostViewController *albumDetailsVC = [[HostViewController alloc] init];
    [self.navigationController pushViewController:albumDetailsVC animated:YES];
    [albumDetailsVC release];
    
}

// 设置segment在section的header上
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    NSString *sectionTitle = [self tableView:tableView titleForHeaderInSection:section];
    if (sectionTitle == nil) {
        return nil;
    }
    // Create header view and add label as a subview
    UIView *sectionView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, tableView.bounds.size.height)] autorelease];
    [sectionView setBackgroundColor:[UIColor whiteColor]];
   // sectionView.userInteractionEnabled = YES;
    [sectionView addSubview:self.segment];
    
    return sectionView;
    
}

// 下面不需要看====我就看
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    return [NSString stringWithFormat:@"section:%ld", section];
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.arr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (self.flag == 0) {
        AlbumDetailsInformationCell *cell = [tableView dequeueReusableCellWithIdentifier:@"detailsInfor"];
        cell.introduction = self.introduction;
        return cell;
    } else if (self.flag == 1) {
        
        static NSString *str = @"datails";
        
        AlbumDetailsCell *cell = [tableView dequeueReusableCellWithIdentifier:str];
        
        if (cell == nil || self.cellTag != 10000 + indexPath.row) {
            
            cell = [[[AlbumDetailsCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:str] autorelease];
            [cell.audioButton addTarget:self action:@selector(playTheAudio:) forControlEvents:UIControlEventTouchUpInside];
        }
        cell.audioButton.tag = indexPath.row + 10000;
        
        if (self.cellTag == 10000 + indexPath.row) {
            [cell.audioButton removeFromSuperview];
            [cell.contentView addSubview:self.audioBtn];
            
            
//            [tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:nil];
        }
        
//        
//        AlbumDetailsCell *cell = [tableView dequeueReusableCellWithIdentifier:@"datails"];
        AlbumDatailsOfList *datailList = [self.arr objectAtIndex:indexPath.row];
       
        
        
        cell.albumDatailsOfList = datailList;
        
        return cell;
        
    } else if (self.flag == 2) {
        
//        if (self.arr.count < 2) {
//            self.whiteView.hidden = NO;
//        } else {
//            self.whiteView.hidden = YES;
//        }
        
        AlbumOfListCell *cell = [tableView dequeueReusableCellWithIdentifier:@"datailsRelated"];
        AlbumOfList *albumList = [self.arr objectAtIndex:indexPath.row];
        cell.albumList = albumList;
        return cell;
        
        
        
    }
    return  nil;
}

-(instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.flag = 1;
        
        self.pageId = 1;
        self.albumPageId = 1;
        self.arr = [NSMutableArray array];
        self.relatedArr = [NSMutableArray array];
        self.inforArr = [NSMutableArray array];
        self.listArr = [NSMutableArray array];
        NSLog(@"adf@");
       // [self relatedHandleData];
    }
    return self;
}

- (void)setupRefresh
{
    //    NSLog(@"进入了setupRefresh");
    // 1.下拉刷新(进入刷新状态就会调用self的headerRereshing)
    
//    [self.detailsTableView addHeaderWithTarget:self action:@selector(headerRereshing)];
//    //进入刷新状态(一进入程序就下拉刷新)
//    [self.detailsTableView headerBeginRefreshing];
    
    
    // 2.上拉加载更多(进入刷新状态就会调用self的footerRereshing)
    [self.detailsTableView addFooterWithTarget:self action:@selector(footerRereshing)];
}



#pragma mark 开始进入刷新状态
- (void)headerRereshing
{
    
    //1. 在这调用请求网络数据方法（刷新数据）
    
    //2. 2秒后刷新表格UI
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        // 刷新表格
        [self.detailsTableView reloadData];
        
        // (最好在刷新表格后调用)调用endRefreshing可以结束刷新状态
        [self.detailsTableView headerEndRefreshing];
    });
}

//   进入加载状态
- (void)footerRereshing
{
    //1. 拼接口等操作
    // 请求加载数据
    
    // 如果是音频列表
    if (self.flag == 1) {
        
        
        // 小于最大页码
        if (self.pageId < self.maxPageId) {
            // 页码加1
            ++self.pageId;
            
            NSString *pageId = [NSString stringWithFormat:@"%ld", self.pageId];
            NSString *str =[NSString stringWithFormat:@"http://mobile.ximalaya.com/mobile/others/ca/album/track/%@/true/%@/30?device=iPhone", self.albumOfList.id, pageId] ;
            
            // self.flag = 1;
            [NetHandler getDataWithURL:str completion:^(NSData *data) {
                
                id result = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
                
                
                self.maxPageId = [[[result objectForKey:@"tracks"] objectForKey:@"maxPageId"] intValue];
                self.pageId = [[[result objectForKey:@"tracks"] objectForKey:@"pageId"] intValue];
                NSMutableArray *array = [[result objectForKey:@"tracks"] objectForKey:@"list"];
                
                
                for (NSDictionary *dic in array) {
                    AlbumDatailsOfList *list = [[AlbumDatailsOfList alloc] initWithDictionary:dic];
                    [self.listArr addObject:list];
                    [list release];
                }
                [self.arr removeAllObjects];
                [self.arr addObjectsFromArray:self.listArr];
                // 刷新数据
                [self.detailsTableView reloadData];
            }];
 
        }

    } else if (self.flag == 2) {
        
        if (self.albumPageId < self.maxAlbumPageId) {
            
            NSLog(@"%ld", self.maxAlbumPageId);
            ++self.albumPageId;
            
            NSString *page = [NSString stringWithFormat:@"%ld", self.albumPageId];
            NSString *path =[NSString stringWithFormat: @"http://mobile.ximalaya.com/mobile/others/ca/album/%@/%@/30?device=iPhone", self.introduction.uid, page] ;
            [NetHandler getDataWithURL:path completion:^(NSData *data) {
                
                id result = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
                
                NSMutableArray *array = [result objectForKey:@"list"];
                for (NSDictionary *dic in array) {
                    AlbumOfList *albumlist = [[AlbumOfList alloc] initWithDictionary:dic];
                    
                    if (albumlist.id != self.albumOfList.id) {
                        [self.relatedArr addObject:albumlist];
                    }
                    
                    [albumlist release];
                }
                [self.arr removeAllObjects];
                [self.arr addObjectsFromArray:self.relatedArr];
                
                [self.detailsTableView reloadData];
                //[self.arr addObjectsFromArray:self.relatedArr];
            }];

            
        }
         
    }
    
    // 2.2秒后刷新表格UI
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        // 刷新表格
        
        // (最好在刷新表格后调用)调用endRefreshing可以结束刷新状态
        [self.detailsTableView reloadData];
        [self.detailsTableView footerEndRefreshing];
    });
}

#pragma mark 列表的数据解析
- (void)listHandleData
{
    NSString *pageId = [NSString stringWithFormat:@"%ld", self.pageId];
    NSString *str =[NSString stringWithFormat:@"http://mobile.ximalaya.com/mobile/others/ca/album/track/%@/true/%@/30?device=iPhone", self.albumOfList.id, pageId] ;
    
   // self.flag = 1;
    [NetHandler getDataWithURL:str completion:^(NSData *data) {
        
        id result = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
       // 处理album
        NSDictionary *introDic = [result objectForKey:@"album"];

        self.introduction = [[Introduction alloc] initWithDictionary:introDic];
        [self relatedHandleData];
        [self.inforArr addObject:self.introduction];
        
        // 显示专辑信息
        [self setNickInfor:self.introduction];
        
        [_introduction release];

        self.maxPageId = [[[result objectForKey:@"tracks"] objectForKey:@"maxPageId"] intValue];
        self.pageId = [[[result objectForKey:@"tracks"] objectForKey:@"pageId"] intValue];
        NSMutableArray *array = [[result objectForKey:@"tracks"] objectForKey:@"list"];
        
        
        for (NSDictionary *dic in array) {
            AlbumDatailsOfList *list = [[AlbumDatailsOfList alloc] initWithDictionary:dic];
            [self.listArr addObject:list];
            [list release];
        }
        [self.arr addObjectsFromArray:self.listArr];
        // 刷新数据
        [self.detailsTableView reloadData];
    }];
}

#pragma mark 相关专辑的数据解析
- (void)relatedHandleData
{
    NSString *page = [NSString stringWithFormat:@"%ld", self.albumPageId];
    NSString *path =[NSString stringWithFormat: @"http://mobile.ximalaya.com/mobile/others/ca/album/%@/%@/30?device=iPhone", self.introduction.uid, page] ;
    [NetHandler getDataWithURL:path completion:^(NSData *data) {
        
        id result = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];

        self.albumPageId = [[result objectForKey:@"pageId"] integerValue];
        self.maxAlbumPageId = [[result objectForKey:@"maxPageId"] integerValue];
        NSMutableArray *array = [result objectForKey:@"list"];
        for (NSDictionary *dic in array) {
            AlbumOfList *albumlist = [[AlbumOfList alloc] initWithDictionary:dic];
            
            if (albumlist.id != self.albumOfList.id) {
                [self.relatedArr addObject:albumlist];
            }
            
            [albumlist release];
        }
        
        //[self.arr addObjectsFromArray:self.relatedArr];
    }];
}

#pragma mark 点击播放的按钮

- (void)playTheAudio:(AudioButton *)button
{
    
    self.audioBtn = button;

    self.cellTag = button.tag;

    _audioPlayer =  [AudioPlayer shareInstance];
    _audioPlayer.imagePath = [[self.listArr objectAtIndex: button.tag - 10000] coverLarge];
    if ([_audioPlayer.button isEqual: button]) {
        
        [_audioPlayer play];
        
    } else {
        _mainPlayVC = [MainPlayerViewController defaultPlayer];
        [_mainPlayVC.listArr removeAllObjects];
        [_mainPlayVC.listArr addObjectsFromArray:self.arr];
        _mainPlayVC.index = button.tag - 10000;
        _mainPlayVC.trackId = [[self.listArr objectAtIndex:button.tag - 10000] trackId];
        [_mainPlayVC showDetailInformation];
        [_audioPlayer stop];
        
        _audioPlayer.button = button;
        
        _audioPlayer.url = [NSURL URLWithString:[[self.listArr objectAtIndex:button.tag - 10000] playUrl64] ];
        
        [_audioPlayer play];
    }
    
}


#pragma mark segment点击方法
- (void)changeSegment:(UISegmentedControl *)segment
{
    if (segment.selectedSegmentIndex == 1) {
        self.flag = 1;
        if (self.listArr.count == 0) {
            
            [self.arr removeAllObjects];
            [self.arr addObjectsFromArray:self.listArr];
            self.detailsTableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
            [self.detailsTableView reloadData];
            
        } else {
            
            [self.arr removeAllObjects];
            [self.arr addObjectsFromArray:self.listArr];
            self.detailsTableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
            [self.detailsTableView reloadData];
            
        }
   
    } else if (segment.selectedSegmentIndex == 0) {

        self.flag = 0;
        [self.arr removeAllObjects];
        [self.arr addObjectsFromArray:self.inforArr];
        self.detailsTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        [self.detailsTableView reloadData];
        
    } else if (segment.selectedSegmentIndex == 2) {
        
        self.detailsTableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
        self.flag = 2;
        if (self.relatedArr.count != 0) {
        // 先移除数组中原有的数据 再将新的数组添加进去
        [self.arr removeAllObjects];
        [self.arr addObjectsFromArray:self.relatedArr];
        [self.detailsTableView reloadData];
        } else {
            
            [self.arr removeAllObjects];
            [self.arr addObjectsFromArray:self.relatedArr];
//            self.detailsTableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
            [self.detailsTableView reloadData];
        }
    }
}

#pragma mark 设置cell的高度
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (self.flag == 0) {
        return [UIScreen mainScreen].bounds.size.height - DETAIL_HIGHT - 40;
    } else if (self.flag == 1) {
        return 100;
    } else if (self.flag == 2) {
        return 80;
    }
    return 0;
}

#pragma mark 点击cell触发的方法
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    if (self.flag == 2) {
        
        AlbumDetailsViewController *albumDetailsVC = [[AlbumDetailsViewController alloc] init];
        albumDetailsVC.albumOfList = [self.arr objectAtIndex:indexPath.row];
        [self.navigationController pushViewController:albumDetailsVC animated:YES];
        [albumDetailsVC release];
        
    } else if (self.flag == 1) {
        
        self.cell = (AlbumDetailsCell *)[tableView cellForRowAtIndexPath:indexPath];
        
        AlbumDatailsOfList *dataList = [self.arr objectAtIndex:indexPath.row];
        
        _mainPlayVC = [MainPlayerViewController defaultPlayer];
        
        _mainPlayVC.albumDatail = dataList;
        _mainPlayVC.trackId = dataList.trackId;
        _audioPlayer = [AudioPlayer shareInstance];
        [_mainPlayVC.listArr removeAllObjects];
        [_mainPlayVC.listArr addObjectsFromArray:self.arr];
        _mainPlayVC.index = indexPath.row;
        _mainPlayVC.navi = self.navigationController;
        if (![_audioPlayer.button isEqual:_cell.audioButton]) {
            
            [_audioPlayer stop];
            self.audioBtn = _cell.audioButton;
            
        
             _audioPlayer.button = _cell.audioButton;
            self.cellTag = _cell.audioButton.tag;
            _audioPlayer.url = [NSURL URLWithString:dataList.playUrl64];
            [_audioPlayer play];
        
        }
       
        
       // _mainPlayVC.audioButton = _cell.audioButton;
//        UINavigationController *naviVC = [[UINavigationController alloc] initWithRootViewController:_mainPlayVC];
        [_mainPlayVC showDetailInformation];
        
//        [self presentViewController:_mainPlayVC animated:YES completion:^{
//            
//            
//        }];
        
        
        
        
        CATransition *transition = [CATransition animation];
        transition.duration = 0.5f;
        transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
        transition.type = @"push";
        transition.subtype = kCATransitionFromTop;
        transition.delegate = self;
        [self.navigationController.view.layer addAnimation:transition forKey:nil];
        
        [self.navigationController pushViewController:_mainPlayVC animated:NO];
        
    }
    
}






#pragma mark 释放
-(void)dealloc
{
//    [_detailsTableView release];
    
#pragma mark 崩溃的
    //[_detailsTableView release];
    [_listArr release];
    [_imageView release];
    [_segment release];
    [_arr release];
    [_relatedArr release];
    [_introduction release];
    [_nickname release];
    [_albumImageView release];
    [_avatarImageView release];
    [super dealloc];
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
